﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using Microsoft.Win32;

namespace GISSystem.Class
{

    public class Ini
    {
        //调用ini相关的API
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileInt(string lpApplicationName, string lpKeyName, int nDefault, string lpFileName);
        [DllImport("kernel32")]
        private static extern bool GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
        [DllImport("kernel32")]
        private static extern bool WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
        [DllImport("kernel32")]
        private static extern bool GetPrivateProfileSection(string lpAppName, string lpReturnedString, int nSize, string lpFileName);
        [DllImport("kernel32")]
        private static extern bool WritePrivateProfileSection(string lpAppName, string lpString, string lpFileName);

        #region 全局地图窗口相关配置
        /// <summary>
        /// 读取是否显示全图窗口(预览窗口)
        /// </summary>
        /// <returns></returns>
        public static bool GetOverviewFormShow()
        {
            StringBuilder strbld = new StringBuilder(256);
            GetPrivateProfileString("OverviewForm", "Show", "Yes", strbld, strbld.Capacity, Configuration.ConfigPath);
            string s = strbld.ToString();
            return (s == "Yes");
        }

        /// <summary>
        /// 保存是否显示全图窗口(预览窗口)
        /// </summary>
        /// <param name="show"></param>
        public static void SetOverviewFormShow(bool show)
        {
            string s = show ? "Yes" : "No";
            WritePrivateProfileString("OverviewForm", "Show", s, Configuration.ConfigPath);
        }

        /// <summary>
        /// 通过读取ini配置文件获得全图窗口的初始化位置
        /// </summary>
        /// <returns></returns>
        public static Point GetOverviewFormLocation()
        {
            int x = GetPrivateProfileInt("OverviewForm", "LocationX", -1, Configuration.ConfigPath);
            int y = GetPrivateProfileInt("OverviewForm", "LocationY", -1, Configuration.ConfigPath);
            Point p = new Point(x, y);

            return p;
        }

        /// <summary>
        /// 保存全局地图窗口位置
        /// </summary>
        /// <param name="loc">位置</param>
        public static void SetOverviewFormLocation(Point loc)
        {
            int x = loc.X;
            int y = loc.Y;
            WritePrivateProfileString("OverviewForm", "LocationX", x.ToString(), Configuration.ConfigPath);
            WritePrivateProfileString("OverviewForm", "LocationY", y.ToString(), Configuration.ConfigPath);
        }

        /// <summary>
        /// 获取全图窗口的宽度
        /// </summary>
        /// <returns></returns>
        public static int GetOverviewFormWidth()
        {
            int width = GetPrivateProfileInt("OverviewForm", "Width", 288, Configuration.ConfigPath);

            return width;
        }

        /// <summary>
        /// 保存全局地图窗口的宽度
        /// </summary>
        /// <param name="width">窗口宽度</param>
        public static void SetOverviewFormWidth(int width)
        {
            WritePrivateProfileString("OverviewForm", "Width", width.ToString(), Configuration.ConfigPath);
        }

        /// <summary>
        /// 获取全图窗口的高度
        /// </summary>
        /// <returns></returns>
        public static int GetOverviewFormHeight()
        {
            int height = GetPrivateProfileInt("OverviewForm", "Height", 260, Configuration.ConfigPath);
            return height;
        }

        /// <summary>
        /// 保存全局地图窗口的高度
        /// </summary>
        /// <param name="height">高度</param>
        public static void SetOverviewFormHeight(int height)
        {
            WritePrivateProfileString("OverviewForm", "Height", height.ToString(), Configuration.ConfigPath);
        }
        #endregion

        //public static Color GetMainFormStyle()
        //{

        //}
    }
}
